<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>


<form:form id="QuestionForm" modelAttribute="question" method="post" cssClass="inline">
    <fieldset>
		<legend>Ask Question</legend>
		<spring:hasBindErrors name="question">
			<div class="error">
				<spring:bind path="question.*">
					<c:forEach items="${status.errorMessages}" var="error">
						<span><c:out value="${error}"/></span><br>
					</c:forEach>
				</spring:bind>
			</div>
		</spring:hasBindErrors>
		<form:hidden id="id" path="id"/>
		<div class="span-17">
			<label for="title">title:</label>
			<form:input class="span-11" id="title" path="title"/><br/>
		</div>
		<div class="span-17">
			<label for="title">tags:</label>
			<form:input class="span-2" id="tag1" path="tag1"/>
			<form:input class="span-2" id="tag2" path="tag2"/>
			<form:input class="span-2" id="tag3" path="tag3"/>
			<form:input class="span-2" id="tag4" path="tag4"/>
			<form:input class="span-2" id="tag5" path="tag5"/>
			<br/>
		</div>
		<div class="span-17">		
			<form:textarea id="content" path="content" style="width:670px;height:200px;"/><br/>
		</div>
		<div class="span-9">
			<a href="javascript:questionSubmit()" id='btn_submit_question' class='rndbutton'><span>Post question</span></a>
		</div>
	</fieldset>
</form:form>
<script type='text/javascript'>
<!--
	var editor;
	$(document).ready(function(){
		editor = KindEditor.create('textarea[name="content"]',{
			id : 'content',
			resizeMode : 1,
			shadowMode : false,
			allowPreviewEmoticons : false,
			allowUpload : true,
			syncType : 'form',
			urlType : 'domain',
			cssPath : '<c:url value="/resources/js/plugins/code/prettify.css" />',
			uploadJson : '<c:url value="/image/upload" />',
			items : ['bold', 'italic', 'underline', 'strikethrough', 'removeformat','|',
'formatblock', 'fontname', 'fontsize','|',
'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent','|',
'link', 'unlink', 'emoticons', 'image', 'flash', '|',
'selectall','source' ,'about']
		});
	});
//-->
</script>
<script type='text/javascript'>
<!--
	$(document).ready(function(){
		$("#QuestionForm").ajaxStart(function(){
				$('#btn_submit_question span').html('posting...');
	    });
		$("#QuestionForm").ajaxComplete(function(event,request, settings){
				$('#btn_submit_question span').html('Post');
	    }); 
	});

	function questionSubmit(){
		editor.sync();
		var form = $('#QuestionForm').serialize();
		$.post('<c:url value="/ajax/questions/ask/submit"/>',form,function(data){
			if (data.error == 0){
				location.href = '<c:url value="/questions/"/>'+data.questionId;
			} else if(data.error == 1) {
	    		alert(data.messages);
			}else if (data.error == 2){
				popupLogin();
			} else {
				alert(data);
			}
		});
	}
//-->
</script>
